<template >
  <div style="display: flex; flex-direction: column;">
    <div style="overflow: hidden;display: flex;flex-direction: row;align-items: center;">
      <el-card class="box-card">
        <div style="overflow: hidden;display: flex;flex-direction: row;align-items: center;">
          <el-input
              v-model="searchInput"
              placeholder="搜索单词"
              size="small"
              clearable
              style="width: 200px;height: 24px;margin-top: 1px;margin-right: 10px"
          >
            <template #prefix>
              <el-icon><search /></el-icon>
            </template>
          </el-input>
          <el-button type="primary" style="height: 24px" @click="search">搜索</el-button>
        </div>
        <div style="margin-top: 10px">
          <el-radio v-model="mode" label="英文" >英文</el-radio>
          <el-radio v-model="mode" label="中文">中文</el-radio
          >
        </div>
      </el-card>

    </div>
    <div style="padding: 10px">
      <el-table :data="tableData" stripe border style="width: 100%">
        <el-table-column prop="wid" label="ID" />
        <el-table-column prop="bid" label="单词书ID"  />
        <el-table-column prop="wordstr" label="单词" />
        <el-table-column prop="pron" label="英标"/>
        <el-table-column prop="paraphrase" label="释义" />
      </el-table>
    </div>
    <div>
      <el-pagination
          v-model:currentPage="currentPage"
          :page-size="pageSize"
          :page-sizes="[5, 10, 20]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
      />
    </div>
  </div>

</template>

<script>
import request from "@/utils/request";

export default {
  name: "SearchWord",
  data(){
    return {
      searchInput: "",
      tableData:[],
      mode:"英文",
      currentPage:1,
      pageSize:10,
      total:0,
      form:{}
    }
  },
  methods:{
    search(){
      request.get("/api/word/search",{
        params:{
          pageNum:this.currentPage,
          pageSize:this.pageSize,
          mode:this.mode,
          search:this.searchInput
        }
      }).then(res => {
        if (res.code === '0') {
          console.log("查询成功！")
          this.tableData = res.data.records
          this.total = res.data.total
        } else {
          this.$message({
            type: "error",
            message: res.msg
          })
        }
      })
    },
    handleSizeChange(pageSize){
      this.pageSize = pageSize
      this.search()
    },
    handleCurrentChange(pageNum){
      this.currentPage = pageNum
      this.search()
    }
  }
}
</script>

<style scoped>
  .box-card{
    margin:10px;
  }
</style>
